﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.InsertLocationInsideSeam.CApIlisManipulator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.InsertLocationInsideSeam;

internal class CApIlisManipulator
{
  private const double _MANIPULATOR_FACTOR = 50.0;
  private double _manipulatorLength = 100.0;
  private TxManipulator _manipulator;
  private TxColor _manipulatorColor;

  public CApIlisManipulator(TxTransformation location)
  {
    this._manipulatorColor = new TxColor(byte.MaxValue, byte.MaxValue, (byte) 0);
    this.CreateManipulator(location);
  }

  public TxTransformation AbsoluteLocation
  {
    get
    {
      return TxManipulator.op_Inequality(this._manipulator, (ITxObject) null) ? this._manipulator.AbsoluteLocation : new TxTransformation();
    }
    set
    {
      if (!TxManipulator.op_Inequality(this._manipulator, (ITxObject) null))
        return;
      this.ChangeManipulatorLocation(value);
    }
  }

  public TxTransformation ProjectedLocation { get; set; }

  private void CreateManipulator(TxTransformation location)
  {
    this._manipulatorLength = (double) TxApplication.ViewersManager.GraphicViewer.ViewRectangle.Width / 50.0;
    TxManipulatorLineElementData manipulatorLineElementData1 = new TxManipulatorLineElementData(new TxTransformation(), new TxVector(-1.0 * this._manipulatorLength / 2.0, 0.0, 0.0), new TxVector(this._manipulatorLength / 2.0, 0.0, 0.0));
    ((TxManipulatorElementData) manipulatorLineElementData1).Color = this._manipulatorColor;
    ((TxManipulatorElementData) manipulatorLineElementData1).Pickable = false;
    ((TxManipulatorElementData) manipulatorLineElementData1).AlwaysOnTop = true;
    ((TxManipulatorElementData) manipulatorLineElementData1).Unzoomable = true;
    TxManipulatorLineElementData manipulatorLineElementData2 = new TxManipulatorLineElementData(new TxTransformation(), new TxVector(0.0, -1.0 * this._manipulatorLength / 2.0, 0.0), new TxVector(0.0, this._manipulatorLength / 2.0, 0.0));
    ((TxManipulatorElementData) manipulatorLineElementData2).Color = this._manipulatorColor;
    ((TxManipulatorElementData) manipulatorLineElementData2).Pickable = false;
    ((TxManipulatorElementData) manipulatorLineElementData2).AlwaysOnTop = true;
    ((TxManipulatorElementData) manipulatorLineElementData2).Unzoomable = true;
    TxManipulatorCreationData manipulatorCreationData = new TxManipulatorCreationData();
    ((TxObjectCreationData) manipulatorCreationData).Name = "Manipulator";
    ((TxLocatableObjectCreationData) manipulatorCreationData).AbsoluteLocation = location;
    manipulatorCreationData.InsertElementData((TxManipulatorElementData) manipulatorLineElementData1);
    manipulatorCreationData.InsertElementData((TxManipulatorElementData) manipulatorLineElementData2);
    this._manipulator = TxApplication.ActiveDocument.PhysicalRoot.CreateManipulator(manipulatorCreationData);
    this._manipulator.AbsoluteLocation = location;
    this._manipulator.Display();
  }

  public void ChangeManipulatorLocation(TxTransformation newLocation)
  {
    if (TxManipulator.op_Inequality(this._manipulator, (ITxObject) null))
      this._manipulator.AbsoluteLocation = newLocation;
    else
      this.CreateManipulator(newLocation);
  }

  public void DestroyManipulator()
  {
    if (!TxManipulator.op_Inequality(this._manipulator, (ITxObject) null))
      return;
    this._manipulator.Delete();
    this._manipulator = (TxManipulator) null;
  }
}
